chore(tests): Fix flaky nodb tests due to AlgorithmTest#62035
Open
DerDreschner wants to merge 1 commit into
Open
chore(tests): Fix flaky nodb tests due to AlgorithmTest#62035DerDreschner wants to merge 1 commit into
AlgorithmTest#62035DerDreschner wants to merge 1 commit into
Conversation
AlgorithmTestAlgorithmTest
Contributor
|
Looks like we do the same thing in the only place I could find in real code that uses ec/x: |
come-nc
approved these changes
Jul 13, 2026
mickenordin
approved these changes
Jul 13, 2026
Member
|
@DerDreschner BTW AI written PR descriptions are forbidden: https://github.com/nextcloud/.github/blob/master/AI_POLICY.md#human-written-communication |
Contributor
Author
Ohh, thank you for pointing that out! Will keep that in mind in the future. |
Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
94a67af to
146f2a1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary (AI generated)
The failing test
AlgorithmTest::testEcdsaP256RoundTripis a random flake. The chain:ecKeyPair()generates a fresh EC key each run and builds a JWK fromopenssl_pkey_get_details()['ec']['x']/['y'].BN_bn2bin(), which strips leading zero bytes — so ~1 in 256 coordinates comes back 31 bytes instead of 32.JWK::parseKey()concatenates the decoded coordinates directly into the uncompressed EC point (0x04 || x || y), which OpenSSL requires to be exactly 65 bytes for P-256. A short coordinate produces a malformed point → the warningopenssl_verify(): Supplied key param cannot be coerced into a public key→ verify returnsfalse.RFC 7518 §6.2.1.2 requires JWK coordinates zero-padded to the full field size. Production code already does this correctly (
OCMSignatoryManager::buildEcdsaP256JwkArray) — only the test helper forgot.Why "only on PHP 8.3"?
It actually isn't version-specific — that run was just unlucky. I checked php-src: both PHP 8.3 and 8.5 use the same unpadded
BN_bn2bininopenssl_pkey_get_details(). I then ran a 2000-iteration repro in bothphp:8.3-cliandphp:8.5-rc-clicontainers: both produced short coordinates at the expected ~0.5–0.9% rate, and every short coordinate failed verification. Each CI job generates its own random keys, so with roughly a 1–3% failure chance per job, the 8.3 job happened to draw a bad key while the 8.5 job didn't. A re-run could just as well have failed on 8.5.The fix
In
tests/lib/Security/Signature/Rfc9421/AlgorithmTest.php,ecKeyPair()now pads both coordinates via a newzeroPadCoordinates()helper (as you suggested) — 32 bytes for P-256, 48 for P-384. Verified: 100 consecutive runs of the ECDSA tests in the dev container, all green, and the repro loop shows zero failures with padding on both PHP versions.Checklist
3. to review, feature component)stable32)AI (if applicable)